home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4272 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: cs.ruu.nl!usenet
  2. From: wsldanke@cs.ruu.nl (Wessel Dankers)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: x ^= y ^= x ^= y;
  5. Date: 24 Feb 96 18:00:24 +0100
  6. Organization: Dept of Computer Science, Utrecht University, The Netherlands
  7. Message-ID: <972.6628T1080T1212@cs.ruu.nl>
  8. References: <4glcf7$eou@wn1.sci.kun.nl>
  9. NNTP-Posting-Host: anx1p10.cc.ruu.nl
  10. X-Newsreader: THOR 2.22 (Amiga TCP/IP)
  11.  
  12.  
  13. Olaf Seibert <rhialto@mbfys.kun.nl> wrote:
  14. >In <1286.6624T1439T237@cs.ruu.nl> wsldanke@cs.ruu.nl (Wessel Dankers) writes:
  15. >>Which can of course be rewritten as:
  16. >>
  17. >> x ^= y;
  18. >> y ^= x;
  19. >> x ^= y;
  20. >>
  21. >>or if you want it real fancy:
  22. >>
  23. >> x ^= y ^= x ^= y;
  24.  
  25. >No. you can't do this last step. You are modifying the same variable
  26. >(two variables even) twice between sequence points.
  27.  
  28. It has been tested and used. Remember that the ^= is right associative:
  29. read it as:
  30.  
  31. x ^= (y ^= (x ^= y));
  32.  
  33. The result-value of (x ^= y) is equal to the new value of x, mutatis mutandis
  34. for (y ^= x).
  35.  
  36. --
  37. Wessel Dankers                 _\\|//_            <wsldanke@cs.ruu.nl>
  38.                                ///|\\\
  39. ----------------------------oOO--(_)---OOo----------------------------
  40. `Never imagine yourself not to be otherwise than what it might appear
  41. to others that what you were or might have been was not otherwise than
  42. what you had been would have appeared to them to be otherwise.'
  43.  
  44.